package gx.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import gx.service.PurchaseItemService;


@Controller
@RequestMapping("/mng/count")
public class CountController {
	
	@Autowired
	private PurchaseItemService purchaseItemService;
	
	//2017年每月商品统计入库图表
	@RequestMapping("/purc.jhtml")
	public ModelAndView purc(){
		ModelAndView mav = new ModelAndView("/mng/count/list");
		int year = 2017;
		Map<String, Long> map = purchaseItemService.totaInventory(year);
		StringBuffer m = new StringBuffer();//月份
		StringBuffer data =  new StringBuffer();//数量
		int i =0;
		for(Map.Entry<String, Long> maps : map.entrySet()){
			if(i++ > 0){
				m.append(",");
				data.append(",");
			}
			m.append("'");
			m.append(maps.getKey());
			m.append("'");
			data.append(maps.getValue().longValue());
		}
		mav.addObject("year",year);
		mav.addObject("months", m.toString());
		mav.addObject("datas",data.toString());
		
		//2017年商品分类入库比例图
		 Map<String, Long> map_c = purchaseItemService.totaInventoryByCategory(year);
		 StringBuffer datas2 = new StringBuffer();
		 int j = 0;
		 for(Map.Entry<String, Long> mentry :map_c.entrySet()){
            if(j++ >0){
            	datas2.append(",");
            }
            datas2.append("['"+mentry.getKey()+"',"+ mentry.getValue()+"]");
		 }
		 mav.addObject("datas2", datas2);
		return mav;
	}
}
